var status = 0;
var invs = Array(1, 5);
var invv;
var selected;
var slot_1 = Array();
var slot_2 = Array();
var statsSel;

function start() {
    action(1, 0, 0)
}

function action(e, g, k) {
    if (e != 1) {
        cm.dispose();
        return
    }
    status++;
    if (status == 1) {
        var l = false;
        var a = "I can help you drop a cash item where you stand:\r\n\r\n#b";
        for (var j = 0; j < invs.length; j++) {
            var d = cm.getInventory(invs[j]);
            for (var c = 0; c <= d.getSlotLimit(); c++) {
                if (j == 0) {
                    slot_1.push(c)
                } else {
                    slot_2.push(c)
                }
                var b = d.getItem(c);
                if (b == null) {
                    continue
                }
                var f = b.getItemId();
                if (!cm.isCash(f)) {
                    continue
                }
                l = true;
                a += "#L" + ((invs[j] * 1000) + c) + "##v" + f + "##t" + f + "##l\r\n"
            }
        }
        if (!l) {
            cm.sendOk("You don't have any cash items.");
            cm.dispose();
            return
        }
        cm.askMenu(a + "#k")
    } else {
        if (status == 2) {
            invv = (k / 1000) | 0;
            selected = (k % 1000) | 0;
            var h = cm.getInventory(invv);
            if (selected >= h.getSlotLimit()) {
                cm.sendOk("Error, please try again.");
                cm.dispose();
                return
            }
            if (invv == invs[0]) {
                statsSel = h.getItem(slot_1[selected])
            } else {
                if (invv == invs[1]) {
                    statsSel = h.getItem(slot_2[selected])
                }
            }
            if (statsSel == null) {
                cm.sendOk("Error, please try again.");
                cm.dispose();
                return
            }
            cm.askNumber("You want to drop #v" + statsSel.getItemId() + "##t" + statsSel.getItemId() + "#.\r\nHow many?", 1, 1, statsSel.getQuantity())
        } else {
            if (status == 3) {
                if (!cm.dropItem(selected, invv, k)) {
                    cm.sendOk("Error, please try again!");
                    cm.dispose()
                } else {
                    status = 0;
                    action(1, 0, 0)
                }
            }
        }
    }
};